package com.qingcloud.adminbackend.entity.source;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * <p>
 * 数据库数据源配置信息
 * </p>
 *
 * @author wangjinnan
 * @since 2021-03-17
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("td_data_source_database")
public class DataSourceDatabase implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    private Integer id;

    /**
     * 数据源的ID
     */
    private Integer dsId;

    /**
     * 数据库类型 1-mysql 2-pgsql 3-oracle 4-sqlserver.
     */
    private Integer dbType;

    /**
     * jdbc_url
     */
    private String jdbcUrl;

    /**
     * 数据库IP
     */
    private String ip;

    /**
     * 数据库端口
     */
    private Integer port;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 创建时间
     */
    private String createDt;

    /**
     * 数据库名称
     */
    private String catalog;

    public static String check(DataSourceDatabase database) {
        if (database == null)
            return "对象不能为空";
        if (database.getIp() == null)
            return "ip参数不能为空";
        if (database.getDbType() == null)
            return "dbType参数不能为空";
        if (database.getPort() == null)
            return "port参数不能为空";
        if (database.getDsId() == null)
            return "dsId参数不能为空";
        if (database.getUsername() == null)
            return "username参数不能为空";
        if (database.getPassword() == null)
            return "password参数不能为空";
        if (database.getCatalog() == null)
            return "catalog参数不能为空";
        return "true";
    }

}
